<template>
	<view class="container" @tap="isLogin?goPageUserInfo():goPageLogin()">
		 <view class="left">
		    <view class="img"><img :src="isLogin?userInfo.avatarUrl:'../../static/images/user/ico.png'"/></view>
		        <view class="userName" v-if="isLogin">
		            <view class="nickName">{{userInfo.nickName}}</view>
					<span class="number">{{userInfo.number}}</span>
					<!-- <span class="identity">{{roleInfoList[userInfo.role] || roleInfoList[2]}}</span> -->
		        </view>
				<view class="submitLogin" v-else>
					<view>
						登录/注册
					</view>
				</view>
		    </view>
		<view class="right"><uni-icons type="right" size="15"></uni-icons></view>
	</view>
</template>

<script>
import { getIsLogin,getToken,getUserInfo } from '../../utils/auth'
import request from '../../utils/request.js'
import {mapState} from 'vuex'
import config from '../../config.js'
	export default {
		data() {
			return {
				isLogin: false,
				userInfo: {},
				roleInfoList: ['管理员','医生','患者'],
			}
		},
		mounted() {
			//初始化数据
			if(getIsLogin() && getIsLogin() == true) {
				this.getUserInfo()
			}
		},
		computed:{
		},
		methods: {
			//获取用户信息
			getUserInfo() {
				// request({
				// 	url: '/userInfo/getByToken',
				// }).then(res => {
				// 	console.log(res)
				// 	this.userInfo = res.data
				// 	this.isLogin = getIsLogin() || false
				// })
				this.userInfo = getUserInfo() || {}
				this.isLogin = getIsLogin() || false
			},
			//跳转个人信息页面
			goPageUserInfo() {
				uni.navigateTo({
					url: '/pages/mine/info/index'
				})
			},
			//跳转登录页面
			goPageLogin() {
				uni.navigateTo({
					url: '/pages/login'
				})
			}
		}
	}
</script>

<style lang="scss">
.container {
	padding: 20rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-top: 180rpx;
	margin-bottom: 40rpx;
	height: 170rpx;
	
	.left {
	    display: flex;
	    justify-content: center;
	    align-items: center;
		
		
		img {
		    width: 120rpx;
		    height: 120rpx;
			border-radius: 50%;
		}
		
		.userName {
		    margin-left: 40rpx;
			
			.nickName {
				font-weight: 600;
				font-size: 38rpx;
				margin-bottom: 10rpx;
			}
			
			
			.number,
			.identity {
				font-size: 20rpx;
				padding: 2rpx 10rpx;
				border-radius: 15px;
				background-color: #EFF8FB;
				font-weight: 100;
			}
			
			.identity {
				margin-left: 40rpx;
			}
			
		}
		
		.submitLogin {
			margin-left: 40rpx;
		}
	}
}

</style>
